<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
<title>Forget Password</title>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="defaultf.css" rel="stylesheet" type="text/css" media="all" />
<link rel="stylesheet" type="text/css" href="http://localhost/Eldercare/jquery/easyui.css">
    <link rel="stylesheet" type="text/css" href="http://localhost/Eldercare/jquery/icon.css">
    <script type="text/javascript" src="http://localhost/Eldercare/jquery/jquery-1.6.min.js"></script>
	<script type="text/javascript" src="http://localhost/Eldercare/jquery/jquery-1.4.4.min.js"></script>
    <script type="text/javascript" src="http://localhost/Eldercare/jquery/jquery.easyui.min.js"></script>

<script type="text/javascript">

</script>
</head>
        <style type="text/css">
            body {
                background: #FFFFFF url("images/bg.png") repeat;
                background-attachment:fixed;
            }
			.button 
			{
        background-color:beige;
        cursor:pointer; }
		
		.btn
		{
			background-color:#FFF5EE;
			cursor:pointer;
		}
    
        </style>

<body>
<div id="wrap">
<div id="header-wrapper">
<div id="header" class="container">
	<div id="logo">
	<img src="http://localhost/Eldercare/images/eldercare.gif" alt="" title="" border="0" width="270" height="70"/>
	</div>
</p>
<br/>
<br/>
</div>
</div>
</div>
<div id="menu-wrapper">
	<div id="menu">
		<ul>
			<li class="current_page_item" ><a href="" accesskey="1" title="">Forget Password</a></li>
		</ul>
	</div>
	</div>
<div id="wrap-content" style="margin:0px auto 0px auto; padding: 10px">
<form action="CMSUPasswordemail.php" method="post" name="formLogin" style="margin:0px auto 0px auto;">

 <?php
   if(empty($_POST["Username"]) && ($_POST["Email"]))
   {
	   Header ("Location:forgetpassword.php");
   }
 
	if (!empty($_POST["Username"]) && ($_POST["Email"]))
	{
		$checkanswer = $_POST["Username"];
		$checkans = $_POST["Email"];
		$conn = mysql_connect ("localhost", "root", "" ) or die ("Can't connect to database.");
		$db = mysql_select_db ("eldercaredb" , $conn);
		
		$retrieve = "Select * from user where Username= '$checkanswer'";
		$sql = "Select * from user where Email= '$checkans'";
		$result = @mysql_query($sql);
		$username = mysql_query($retrieve);
		$row = mysql_fetch_array ($username);
		if ($row["Username"] == $checkanswer)
		{
  			if($row["UserType"]=="Therapy Assistant")
			{
				echo'<script type="text/javascript">alert("Please look for your Centre Manager!")</script>';
			}
			else
			{
				$pass = rand(); 
				$passHashed = md5($pass); 
				$pass = substr($pass, 0, 7); 
				
				$query = mysql_query ("UPDATE user SET Password = '$passHashed' WHERE Username='$checkanswer'");
				if($query){
					echo "<p align = 'center'>Your new password is: ". $pass;
					//echo "<p align = 'center'><a href='Firstphp.php'><br> Back to Login.</a>";
					$_SESSION["Username"] = 0;
				}
				else
				{
					echo 'Please try again';
					$_SESSION["Username"] = 0;
				}
			}
		}
		
		else
			{

				echo "<p align='center'> <font color=red> You've entered the wrong Username or Username, please check again!";
				//echo "<p align = 'center'><a href='Forgetpassword.php'><br> Please click here to enter again.</a>";
			}
	
	}	
	?>
</form>
</div>
</body>
</html>
